home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / Log Histogram < prev    next >
Text File  |  1995-12-31  |  2KB  |  71 lines

  1. #pragma rtGlobals=1
  2.  
  3. //    Version 1.01, 5/17/94
  4. //        Used Wave/D instead of Wave in several places.
  5. //    Version 1.10, 12/28/95
  6. //        Updated for Igor Pro 3.0. Removed /D which is no longer needed.
  7.  
  8. //    DoLogHist(sw, dwX, dwY, startX, logDeltaX)
  9. //        Creates the logarithmic histogram of the source wave by putting
  10. //        the appropriate numbers in the destination waves.
  11. //        sw is the source wave.
  12. //        dwX is the destination x wave.
  13. //        dwY is the destination y wave.
  14. //        startX, logDeltaX are explained below. See LogHist().
  15. Function DoLogHist(sw, dwX, dwY, startX, logDeltaX)
  16.     Wave sw, dwX, dwY
  17.     Variable startX, logDeltaX
  18.     
  19.     Variable p, pp, npnts
  20.     
  21.     // first find bin edges and put them in dwX
  22.     npnts = numpnts(dwX)
  23.     p = 0
  24.     do
  25.         dwX[p] = startX + 10^(p*logDeltaX)
  26.         p += 1
  27.     while (p < npnts)
  28.     
  29.     // now find which bin each point of dwY belongs in
  30.     npnts = numpnts(sw)
  31.     p = 0
  32.     do
  33.         pp = (log(sw[p]) - startX) / logDeltaX
  34.         dwY[pp] += 1
  35.         p += 1
  36.     while (p < npnts)
  37. End    
  38.  
  39. //    LogHist(sourceWave, numBins, startX, logDeltaX)
  40. //        Creates XY pair of waves that represent the logarithmic histogram of the source wave.
  41. //        If the source wave is named “data” then the output waves will be named “data_hx” and “data_hy”.
  42. //        numBins specifies the number of bins in the histogram.
  43. //        startX specifies the X coordinate of the left edge of first bin. The bin starts at 10^startX.
  44. //        logDeltaX determines the bin width. logDeltaX=1.0 gives you 1 decade/bin.
  45. //    Example
  46. //        Make/N=100 test = 10^(1+abs(gnoise(3)))
  47. //        Display test; ModifyGraph log(left)=1, mode=8,msize=2
  48. //        LogHist("test",10,0,1)
  49. //        Display test_hy vs test_hx; Modify mode=5, log(bottom)=1
  50. Macro LogHist(sourceWave, numBins, startX, logDeltaX)
  51.     String sourceWave
  52.     Prompt sourceWave, "Source wave", popup, WaveList("*", ";", "")
  53.     Variable numBins = 10
  54.     Prompt numBins, "Number of bins in destination wave"
  55.     Variable startX = 0
  56.     Prompt startX, "Starting X value (first bin starts at 10^startX)"
  57.     Variable logDeltaX = 1.0
  58.     Prompt logDeltaX, "Log delta X value (1.0 gives 1 decade per bin)"
  59.     
  60.     Silent 1
  61.     
  62.     String destXWave, destYWave
  63.     
  64.     // Concoct names for dest waves.
  65.     // This does not work if sourceWave is a full or partial path requiring single quotes (e.g., root:Data:'wave 0').
  66.     destXWave = sourceWave + "_hx"
  67.     destYWave = sourceWave + "_hy"
  68.     Make/O/N=(numBins+1) $destXWave=0, $destYWave=0
  69.     DoLogHist($sourceWave, $destXWave, $destYWave, startX, logDeltaX)
  70. End
  71.